import 'dart:ui';

import 'package:flutter/material.dart';
import 'dart:async';
import 'pages/about_us_page.dart';
import 'pages/home_page.dart';
import 'pages/news_page.dart';
import 'pages/product_page.dart';
class App extends StatefulWidget{
  /**
   *  该写法与上面的写法等价的
   */
  @override
  AppState createState() =>AppState();



}
class AppState extends State<App>{

  //当前选择页面的索引
  int _currentIndex=0;
  HomePage homePage;
  ProductPage productPage;
  NewsPage newsPage;
  About_us_Page about_us_page;

  /**
   * 根据当前索引返回不同页面
   */
  currentPage() {
    switch(_currentIndex){
      case 0:
        if(homePage==null){
          homePage=new HomePage();
        }
        return homePage;
        break;
      case 1:
        if(productPage==null){
          productPage=new ProductPage();
        }
        return productPage;
        break;
      case 2:
        if(newsPage==null){
          newsPage=new NewsPage();
        }
        return newsPage;
        break;
      case 3:
        if(about_us_page==null){
          about_us_page=new About_us_Page();
        }
        return about_us_page;
        break;
    }
  }

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      //工具栏
      appBar: AppBar(
        title: Text('flutter企业站开发'),
        leading: Icon(Icons.home),
        actions: <Widget>[
          Padding(
            //右侧内边距
            padding: EdgeInsets.only(right: 20),
            child:GestureDetector(
              onTap: (){},
              child: Icon(
                Icons.search
              ),
            )
          )
        ],
      ),

      body: currentPage(),
      //底部导航栏
      bottomNavigationBar:BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: _currentIndex,
        onTap: (index){
          setState(() {
            _currentIndex=index;
          });
        },
        items: [
          BottomNavigationBarItem(
            title: Text('首页'),
            icon: Icon(Icons.home),
          ),
          BottomNavigationBarItem(
            title: Text('产品'),
            icon: Icon(Icons.apps),
          ),
          BottomNavigationBarItem(
            title: Text('新闻'),
            icon: Icon(Icons.fiber_new),
          ),
          BottomNavigationBarItem(
            title: Text('关于'),
            icon: Icon(Icons.insert_comment),
          ),
        ],
      )
    );
  }


}